<?php

namespace app\index\controller;

use think\Cache;
use think\Controller;
use think\Db;
use think\Loader;
use think\Request;
use think\Validate;

class Api extends Controller
{
    /**
     * 删除知识点
     * */
    public function delKnowledge()
    {
        $input = Request()->param();

        $id = $input['id'];

        if (empty($id)) apiReturn(2, '知识点ID缺失');

        $info = Db::name('course_knowledge')->where(['id' => $id])->find();
        if ($info) {
            $res = Db::name('course_knowledge')->where(['id' => $id])->delete();
            if ($res) {
                apiReturn(1, '删除成功');
            } else {
                apiReturn(2, '删除失败');
            }
        } else {
            apiReturn(2, '知识点不存在或已删除');
        }
    }

    /**
     * ppt上传成功的fileIndex录入
     * */
    public function updateCourseFileIndex()
    {
        $input = Request()->param();

        $course_id = $input['course_id'];
        $file_index = $input['file_index'];

        if($course_id && $file_index){
            $data = [
                'ppt_file_index' => $file_index,
                'ppt_upload_status' => 0,
                'ppt_upload_error_msg' => ''
            ];
            Db::name('course')->where(['id' => $course_id])->update($data);
        }
    }

    public function test()
    {
        getCourseSonCategoryIds(23, $ids);
        echo "<pre>";
        print_r($ids);
        exit;
    }
}
